package com.haust.content.controller;

import com.haust.commons.exception.DaoException;
import com.haust.commons.pojo.HaustResult;
import com.haust.content.service.ContentService;
import com.haust.pojo.TbContent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
public class ContentController {

    @Autowired
    private ContentService contentService;

    /**
     * 根据种类Id 查询具体的广告内容信息
     *
     * @param categoryId 种类Id
     * @return
     */
    @PostMapping("/backend/content/selectTbContentAllByCategoryId")
    public HaustResult selectTbContentAllByCategoryId(@RequestParam("categoryId") Long categoryId) {
        return contentService.selectTbContentAllByCategoryId(categoryId);
    }

    /**
     * 新增  广告内容
     *
     * @param content
     * @return
     */
    @PostMapping("/backend/content/insertTbContent")
    public HaustResult insertTbContent(TbContent content) {
        try {
            return contentService.insertTbContent(content);
        } catch (DaoException e) {
            e.printStackTrace();
            return HaustResult.error(e.getMessage());
        }

    }

    /**
     * 根据id删除 对应的 广告内容
     *
     * @param id
     * @return
     */
    @PostMapping("/backend/content/deleteContentByIds")
    public HaustResult deleteContentByIds(@RequestParam("id") Long id) {
        try {
            return contentService.deleteContentByIds(id);
        } catch (DaoException e) {
            e.printStackTrace();
            return HaustResult.error(e.getMessage());
        }
    }

}
